// packageE/memberorder/memberorder.js
const app = getApp();
Component({
  properties: {
    datas: {
      type: null,
    },
    component_id: {
      type: null,
    }
  },
  // 私有数据，可用于模板渲染
  data: {
    emptyImage:  `${app.globalData.imgPath}image.png`,
    active: ""
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {},
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {},

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },
  methods: {
    toUrl(e){
      let data = e.currentTarget.dataset;
      // 后续新开发的，尽量orderType 为接口返回的 component_key !!!!（和前端装修后台开发人员约定好命名）
      
      // 暂存，暂时用来兼容处理之前的老开发，后续优化干掉 ========================
      let STATUS = data.id.toString();
      if(data.status !== undefined && data.status !== null) STATUS = data.status;
      let _routerName = "/packageA/member/myOrder_v2/myOrder_v2";
      let status = STATUS;

      if (data.uikey == "U_memberorderlive_install") {
        _routerName = '/packageH/installationSever/installationSeverMemberHome/installationSeverMemberHome';
      }
      if (data.uikey == "U_memberorderlive_install_worker") {
        _routerName = '/packageH/installationSever/installationSeverHome/installationSeverHome';
        status = STATUS == -1 ? 1 : STATUS + 2;
      }
      if (data.uikey == "U_memberordercps") {
        _routerName = STATUS == 3 ? "/packageA/member/order/cpsCoupon/cpsCoupon" : "/packageA/member/order/cpsOrder/cpsOrder";
      }
      if (data.uikey == "U_coupon_store_order") {
        _routerName = '/packageF/consumption/orderList/orderList';
      }
      if (data.uikey == "U_tiktok_cps_order") {
        _routerName = '/packageF/cps/order/order';
      }
      if (data.uikey == "U_meituan_group_buy_order") {
        _routerName = '/mircoApp/meituan_refund/order/order';
      }
      if (data.uikey == "U_unionCps_order") {
        _routerName = '/packageJ/unionCps/order/order';
      }
      if (data.uikey == "U_memberordergroup") {
        status = STATUS == 2 ? 1 : STATUS;
      }
      

      let _oldPluDataCMPT = {
        // 兼容老数据跳转参数问题。
        U_memberorder: "shop",
        U_memberorderhotel: "hotel",
        U_memberorderrelease: "lease_toy",
        U_memberordergroup: "groups",
        U_memberordergroup_ywm: "ywmgroups",
        U_memberordergrab: "grabGroup",
        U_memberordernew_group: "groupWork",
        U_yz_supply_cake: "sachertorte"
      };
      // 暂存，处理老开发 end =====================================

      if (data.text.indexOf("售后") > -1) {
        // 有售后字样，跳转售后页面
        return wx.navigateTo({
          url: "/packageD/member/myOrder/Aftersaleslist/Aftersaleslist?orderType=" + (_oldPluDataCMPT[data.uikey] || data.uikey),
        });
      }
      wx.navigateTo({
        url: _routerName + "?orderType=" + (_oldPluDataCMPT[data.uikey] || data.uikey) + '&status=' + status + "&title=" + (data.name || data.component),
      });
    },
    bindTags(evt) {
      let index = evt.detail.index;
      this.setData({
        active: index,
      });
      if (this.data.datas.list[index].uikey == "U_memberorder_ys") {
        // 益生线下订单
        wx.navigateTo({
          url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=ysSystem",
        });
        return false;
      }
    }
  },
  observers: {},
});